package cn.bs.busuo.mall.service.impl;

import cn.bs.busuo.common.enumerator.ServiceCode;
import cn.bs.busuo.common.ex.ServiceException;
import cn.bs.busuo.common.pojo.vo.PageData;
import cn.bs.busuo.mall.dao.persist.repository.IGoodsRepository;
import cn.bs.busuo.mall.pojo.entity.Goods;
import cn.bs.busuo.mall.service.IGoodsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements IGoodsService {
    @Value("${busuo.dao.default-query-page-size}")
    private Integer defaultQueryPageSize;
    @Autowired
    private IGoodsRepository goodsRepository;

    @Override
    public Goods getStandardById(Long id) {
        Goods standardById = goodsRepository.getStandardById(id);
        if (standardById==null){
            String message = "查询商品详情失败，商品数据不存在！";
            throw new ServiceException(ServiceCode.ERROR_NOT_FOUND, message);
        }
        return standardById;
    }

    @Override
    public PageData<Goods> listByRecommend(Integer pageNum) {
        System.out.println(defaultQueryPageSize);
        return goodsRepository.listByRecommend(pageNum,defaultQueryPageSize);
    }

    @Override
    public PageData<Goods> listByCategory(Long categoryId, Integer pageNum) {
        return goodsRepository.listByCategory(categoryId, pageNum, defaultQueryPageSize);
    }
}
